package com.kagura.ws.config;

import com.kagura.ws.service.ScheduleService;
import com.kagura.ws.service.impl.SchedultServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @PACKAGE_NAME: com.kagura.ws.config
 * @CLASS_NAME: CxfConfig
 * @USER: kagura
 * @Description TODO 发布WebService配置类
 * @Date 2021/5/23 3:12 下午
 * @MONTH_NAME_FULL: 五月
 * @DAY: 23
 * @DAY_NAME_FULL: 星期日
 * @PROJECT_NAME: ws
 **/
@Configuration
public class CxfConfig {
    @Bean("cxfServletRegistration")
    public ServletRegistrationBean dispatcherServlet() {
        // 注册servlet, 拦截/NBA的请求,不设置默认为/services/*
        return new ServletRegistrationBean(new CXFServlet(), "/patients/*");
    }

    // 申明业务处理类，也可以直接在实现类上加@Service
    @Bean
    public ScheduleService scheduleService() {
        return new SchedultServiceImpl();
    }

    // 非必要项
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    // 发布endpoint
    @Bean
    public Endpoint endpoint(ScheduleService scheduleService) {
        EndpointImpl endpoint = new EndpointImpl(springBus(), scheduleService);
        // 发布地址
        endpoint.publish("/patientService");
        return endpoint;
    }
}
